package com.zdp.config;

import com.sendgrid.SendGrid;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author sesshomaru
 * @date 2021/7/8 21:27
 * 配置SendGrid云服务发送邮件
 */
@RequiredArgsConstructor
@Configuration
public class SendGridEmailConfig {

    private final AppProperties appProperties;

    // 只有在有mooc.email-provider.api-key这个key的时候才会加载这个bean
    @ConditionalOnProperty(prefix = "mooc.email-provider", name = "api-key")
    @Bean
    public SendGrid sendGrid() {
        return new SendGrid(appProperties.getEmailProvider().getApiKey());
    }
}
